def sum(n,flor,target):
    sums = 0
    for i in n:
        if isinstance(i, list):
            sums += sum(i,flor+1,target)
        if isinstance(i, int) and flor==target:
            sums +=1
        if isinstance(i, float) and flor==target:
            sums +=1
    return sums
a = eval(input())
target=eval(input())
print(sum(a,1,target))